package com.wxmit.module.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wxmit.base.domain.ApiResult;
import com.wxmit.framework.web.operatelog.Log;
import com.wxmit.framework.web.operatelog.LogModule;
import com.wxmit.framework.web.operatelog.enums.BusinessType;
import com.wxmit.base.validate.AddGroup;
import com.wxmit.base.validate.UpdateGroup;
import com.wxmit.module.system.domain.SysRole;
import com.wxmit.module.system.service.ISysRoleService;
import com.wxmit.system.base.core.IShushanService;
import com.wxmit.system.base.core.ShushanBaseController;
import com.wxmit.system.base.domain.PageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  角色管理
 * @Author huangxiong
 * @Date 2022/7/19 14:50
 * @Version V1.0
 */
@RestController
@RequestMapping("/sys/role")
@LogModule("角色管理")
public class SysRoleController extends ShushanBaseController<ISysRoleService,SysRole,Long> {

    public final static String PERMISSION_PREFIX = "system:role:";

    public SysRoleController(ISysRoleService baseService) {
        super(baseService,PERMISSION_PREFIX);
    }



    @GetMapping("/select")
    public List<SysRole> listSelect(){
        return baseService.listSelect();
    }


    @PutMapping("status/{id}/{status}")
    @Log(module="角色管理",name="更新角色状态",type = BusinessType.UPDATE)
    public void changeStatus(@PathVariable("id") Long id,@PathVariable("status")String status){
        baseService.updateStatus(id,status);
    }

    @GetMapping("/{id:\\d+}")
    @SaCheckPermission(PERMISSION_PREFIX+"query")
    @Override
    public ApiResult<SysRole> get(@PathVariable("id") Long id) {
        return ApiResult.successWithData(baseService.getInfo(id));
    }
}
